package com.huixh.train.business.controller.admin;

import com.huixh.train.business.req.DailyTrainQueryReq;
import com.huixh.train.business.req.DailyTrainSaveReq;
import com.huixh.train.business.resp.DailyTrainQueryResp;
import com.huixh.train.business.service.DailyTrainService;
import com.huixh.train.common.resp.PageResult;
import com.huixh.train.common.resp.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author huixh
 */
@Tag(name = "每日车次管理", description = "每日车次管理")
@Validated
@RestController
@RequestMapping("/admin/dailyTrain")
public class DailyTrainController {
    @Resource
    private DailyTrainService dailyTrainService;

    @Operation(summary = "新增每日车次", method = "POST")
    @PostMapping("/save")
    public Result<?> save(@RequestBody @Valid DailyTrainSaveReq dailyTrainSaveReq) {
        dailyTrainService.save(dailyTrainSaveReq);
        return Result.success();
    }
    @Operation(summary = "查询每日车次列表", method = "POST")
    @PostMapping("/quest-list")
    public PageResult<List<DailyTrainQueryResp>> query(@RequestBody @Valid DailyTrainQueryReq dailyTrainQueryReq) {
        return dailyTrainService.queryList(dailyTrainQueryReq);
    }
    @Operation(summary = "删除每日车次", method = "DELETE")
    @DeleteMapping("/delete/{id}")
    public Result<?> deleteById(@NotNull @PathVariable(name = "id") Long id) {
        dailyTrainService.delete(id);
        return Result.success("删除成功");
    }
    @GetMapping("/gen-daily/{date}")
    @Operation(summary = "生成每日车次", method = "GET",description = "生成某日所有车次信息 车站、车次、车厢、座位")
    public Result<String> genDaily(@PathVariable("date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
        dailyTrainService.genDaily(date);
        return Result.success("生成成功");
    }
}